<%--
  Created by IntelliJ IDEA.
  User: aron
  Date: 2021/2/15
  Time: 16:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<!-- 网页使用的语言 -->
<html lang="zh-CN">
<head>
    <!-- 指定字符集 -->
    <meta charset="utf-8">
    <!-- 使用Edge最新的浏览器的渲染方式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- viewport视口：网页可以根据设置的宽度自动进行适配，在浏览器的内部虚拟一个容器，容器的宽度与设备的宽度相同。
    width: 默认宽度与设备的宽度相同
    initial-scale: 初始的缩放比，为1:1 -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>用户信息管理系统</title>

    <!-- 1. 导入CSS的全局样式 -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- 2. jQuery导入，建议使用1.9以上的版本 -->
    <script src="js/jquery-2.1.0.min.js"></script>
    <!-- 3. 导入bootstrap的js文件 -->
    <script src="js/bootstrap.min.js"></script>
    <style type="text/css">
        td, th {
            text-align: center;
        }
    </style>

    <script>
        function deleteUser(userId, userName) {
            // alert("删除用户" + userId);
            if (confirm("确认删除用户" + userName + "吗？")) {
                location.href = "${pageContext.request.contextPath}/DeleteUserServlet?id="+userId;
            }
        }
    </script>
</head>
<body>
<div class="container">
    <h3 style="text-align: center">用户信息列表</h3>
    <table border="1" class="table table-bordered table-hover">
        <tr class="success">
            <th>编号</th>
            <th>姓名</th>
            <th>性别</th>
            <th>年龄</th>
            <th>籍贯</th>
            <th>QQ</th>
            <th>操作</th>
        </tr>
        <c:forEach items="${pageBean.users}" var="user" varStatus="stat">
            <tr>
                <td>${stat.index}</td>
                <td>${user.name}</td>
                <td>${user.gender}</td>
                <td>${user.age}</td>
                <td>${user.address}</td>
                <td>${user.qq}</td>
                <td>
                    <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/FindUserByIDServlet?id=${user.id}">修改</a>
                    &nbsp;<a class="btn btn-default btn-sm" href="javascript:deleteUser('${user.id}', '${user.name}')">删除</a>
                </td>
            </tr>
        </c:forEach>

        <tr>
            <td colspan="8" align="center"><a class="btn btn-primary" href="add.html">添加联系人</a></td>
        </tr>
    </table>

    <h4>当前第${pageBean.currentPage}页，共${pageBean.totalPage}页</h4>

    <nav aria-label="Page navigation">
        <ul class="pagination">
            <c:if test="${pageBean.currentPage == 1}">
                <li class="disabled">
                    <a href="#" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
            </c:if>
            <c:if test="${pageBean.currentPage != 1}">
                <li>
                    <a href="${pageContext.request.contextPath}/GetUserPagedListServlet?page=${pageBean.currentPage-1}&contentNumOfPage=5" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
            </c:if>
            <c:forEach begin="1" end="${pageBean.totalPage}" varStatus="stat">
                <c:if test="${stat.index == pageBean.currentPage}">
                    <li class="active"><a href="${pageContext.request.contextPath}/GetUserPagedListServlet?page=${stat.index}&contentNumOfPage=5">${stat.index}</a></li>
                </c:if>
                <c:if test="${stat.index != pageBean.currentPage}">
                    <li><a href="${pageContext.request.contextPath}/GetUserPagedListServlet?page=${stat.index}&contentNumOfPage=5">${stat.index}</a></li>
                </c:if>
            </c:forEach>

            <c:if test="${pageBean.currentPage == pageBean.totalPage}">
                <li class="disabled">
                    <a href="#" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            </c:if>
            <c:if test="${pageBean.currentPage != pageBean.totalPage}">
                <li>
                    <a href="${pageContext.request.contextPath}/GetUserPagedListServlet?page=${pageBean.currentPage+1}&contentNumOfPage=5" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            </c:if>

        </ul>
    </nav>
</div>
</body>
</html>
